package com.pinganfu.tesla.iwallet.util;

import android.content.Context;
import android.content.SharedPreferences;

public class SharedPrefUtil {

	public static String getString(Context ctx, String key) {
		return getSharedPref(ctx).getString(key, null);
	}

	public static String getString(Context ctx, String key, String defaultValue) {
		return getSharedPref(ctx).getString(key, defaultValue);
	}

	public static boolean getBoolean(Context ctx, String key) {
		return getSharedPref(ctx).getBoolean(key, false);
	}

	public static boolean getBoolean(Context ctx, String key, boolean defaultValue) {
		return getSharedPref(ctx).getBoolean(key, defaultValue);
	}

	public static void putString(Context ctx, String key, String value) {
		SharedPreferences.Editor editor = getEditor(ctx);
		editor.putString(key, value);
		editor.commit();
	}

	public static void putBoolean(Context ctx, String key, boolean value) {
		SharedPreferences.Editor editor = getEditor(ctx);
		editor.putBoolean(key, value);
		editor.commit();
	}

	private static SharedPreferences getSharedPref(Context ctx) {
		return ctx.getSharedPreferences(Constant.PREFS_NAME, Context.MODE_PRIVATE);
	}

	private static SharedPreferences.Editor getEditor(Context ctx) {
		return getSharedPref(ctx).edit();
	}
}
